package com.hxit.sportem.controller;

import com.hxit.sportem.DTO.DeleteBatchDTO;
import com.hxit.sportem.entity.Equipment;
import com.hxit.sportem.service.EqmentService;
import com.hxit.sportem.utils.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController //异步请求控制器
@Api(value = "提供了用户登录、查询等相关的接口",tags = "器材管理")
@CrossOrigin //允许跨域
public class EqmentController {

    @Resource
    private EqmentService eqmentService;

    /**
     * 器材显示接口
     * @param name
     * @param pageNum
     * @return
     */
    @GetMapping("/showList")
    @ApiOperation(value = "器材显示接口")
    public ResultVo showList(String name , @RequestParam(defaultValue = "1") int pageNum){
        ResultVo resultVo = eqmentService.showList(name , pageNum);
        System.out.println(resultVo);
        return resultVo;
    }
    /**
     * 根据用户id
     */
    @GetMapping("/deleteEqment/{id}")
    public ResultVo deleteUser(@PathVariable("id")Integer id){
        System.out.println(id);
        ResultVo resultVo = eqmentService.deleteEqment(id);
        return resultVo;
    }
    /**
     * 添加器材
     * @RequestBody: 接收前端传递的json对象
     */
    @PostMapping("/addEqment")
    @ApiOperation(value = "器材添加接口")
    @ResponseBody
    public ResultVo addEqment(@RequestBody Equipment equipment){
        System.out.println(equipment);
        return eqmentService.addEqment(equipment);
    }



    /**
     * 根据对象修改器材信息
     * @param
     * @return
     */
    @PostMapping("/updateEqment")
    public ResultVo updateEqment(@RequestBody Equipment equipment){
        return eqmentService.updateEqment(equipment);
    }

    @PostMapping("/deleteBatch")
    public ResultVo deleteBatch(@RequestBody DeleteBatchDTO deleteBatchDTO){
        return eqmentService.deleteBatch(deleteBatchDTO.getIdList());
    }
}
